<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>cx:until-unchanged</title>
      <meta charset="utf-8" />
      <meta name="generator" content="DocBook XSL 2.0 Stylesheets V2.5.0" />
      <link href="css/default.css" rel="stylesheet" type="text/css" />
      <link href="css/db-prism.css" rel="stylesheet" type="text/css" />
      <link rel="stylesheet" href="css/xproc.css" type="text/css" /><script type="text/javascript" src="js/dbmodnizr.js"></script></head>
   <body>
      <div class="page">
         <div class="content">
            <div xmlns:tmpl="http://docbook.org/xslt/titlepage-templates" class="navheader">
               <table border="0" cellpadding="0" cellspacing="0" width="100%" summary="Navigation table">
                  <tr>
                     <td align="left"> <a title="XML Calabash Reference" href="index.html"><img src="img/home.png" alt="Home" border="0" /></a> <a href="cx-sparql.html" title="cx:sparql"><img src="img/prev.png" alt="Prev" border="0" /></a> <a title="XML Calabash Extension Steps" href="cx-steps.html"><img src="img/up.png" alt="Up" border="0" /></a> <a title="cx:uri-info" href="cx-uri-info.html"><img src="img/next.png" alt="Next" border="0" /></a></td>
                     <td align="right"><i>XML Calabash Reference</i> (Version 0.28)</td>
                  </tr>
               </table>
            </div>
            <div class="body">
               <article id="cx-until-unchanged" class="refentry">
                  <div class="content">
                     <div class="refnamediv">
                        <h2>Name</h2>
                        <p><span class="refname">cx:until-unchanged</span><span class="refpurpose"><span class="refpurpose-sep"> — </span><span class="refpurpose-text">Iterates to a fixed point</span><span class="refpurpose-punc">.</span></span></p>
                     </div>
                     <div xmlns:tmpl="http://docbook.org/xslt/titlepage-templates" class="refsynopsisdiv">
                        <h2>Synopsis</h2>
                        <pre class="programlisting language-none line-numbers nopygments"><code>&lt;cx:until-unchanged
  name? = NCName&gt;
    (p:output?,
     p:log?,
     <em>subpipeline</em>)
&lt;/cx:until-unchanged&gt;&gt;</code></pre>
                     </div>
                     <div class="refsection">
                        <div class="refsection-titlepage">
                           <h2>Description</h2>
                        </div>
                        <div class="content">
                           
                           
                           
                           <p>The <code class="tag-element">cx:until-unchanged</code> step is an extension <em>compound</em>
                              step. There's no provision in the language for defining these steps, but that
                              doesn't mean implementors can't.</p>
                           
                           
                           <p>On the first iteration, the <code class="tag-element">cx:until-unchanged</code> step
                              provides (on the <code class="code">#current</code> port) the document that it
                              reads from the default readable port<sup class="footnote"><span class="osq">[</span><a id="cx-until-unchanged.3.3.3" href="#ftn.cx-until-unchanged.3.3.3">3</a><span class="csq">]</span></sup> to the subpipeline it contains.</p>
                           
                           
                           <p>The subpipeline must produce exactly one output document on
                              <code class="tag-element">cx:until-unchanged</code>’s single output port.</p>
                           
                           
                           <p>On the second and subsequent iterations, the result of the preceding
                              iteration is provided on the <code class="code">#current</code> port.</p>
                           
                           
                           <p>Iteration continues until the document produce is
                              <code class="function">deep-equal</code> to the document produced on the
                              previous iteration.</p>
                           
                           
                           <p>Here's a trivial example:</p>
                           
                           
                           <pre class="programlisting language-none line-numbers"><code>&lt;p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:cx="http://xmlcalabash.com/ns/extensions"
                name="main" version="1.0"&gt;
  &lt;p:input port="parameters" kind="parameter"/&gt;
  &lt;p:output port="result" sequence="true" primary="true"/&gt;

  &lt;p:identity name="id"&gt;
    &lt;p:input port="source"&gt;
      &lt;p:inline&gt;&lt;doc&gt;1&lt;/doc&gt;&lt;/p:inline&gt;
    &lt;/p:input&gt;
  &lt;/p:identity&gt;

  &lt;cx:until-unchanged&gt;
    &lt;p:output port="result"/&gt;
    &lt;p:xslt&gt;
      &lt;p:input port="stylesheet"&gt;
        &lt;p:inline&gt;
          &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                          xmlns:xs="http://www.w3.org/2001/XMLSchema"
                          exclude-result-prefixes="xs"
                          version="2.0"&gt;

            &lt;xsl:template match="doc"&gt;
              &lt;xsl:variable name="count" select="xs:integer(.)"/&gt;
              &lt;xsl:choose&gt;
                &lt;xsl:when test="$count &amp;lt; 5"&gt;
                  &lt;doc&gt;&lt;xsl:value-of select="$count+1"/&gt;&lt;/doc&gt;
                &lt;/xsl:when&gt;
                &lt;xsl:otherwise&gt;
                  &lt;xsl:sequence select="."/&gt;
                &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
            &lt;/xsl:template&gt;
          &lt;/xsl:stylesheet&gt;
        &lt;/p:inline&gt;
      &lt;/p:input&gt;
    &lt;/p:xslt&gt;
  &lt;/cx:until-unchanged&gt;

&lt;/p:declare-step&gt;</code></pre>
                           
                           
                           <p>The stylesheet adds one to the integer value of the document that it
                              is styling as long as the value is less than 5.</p>
                           
                           
                           <p>The result of running this pipeline is that the stylesheet is run
                              five times, producing documents with the “values” 2, 3, 4, 5, 5. At that
                              point the loop terminates and the last document,</p>
                           
                           
                           <pre class="programlisting language-none line-numbers"><code>&lt;doc&gt;5&lt;/doc&gt;</code></pre>
                           
                           
                           <p>is returned.</p>
                           
                           </div>
                     </div>
                  </div>
                  <div class="footnotes">
                     <hr width="100" align="left" class="footnotes-divider" />
                     <div class="footnote">
                        <div class="footnote-wrapper">
                           <div class="footnote-symbol-wrapper">
                              <p><sup><span class="osq">[</span><a href="#cx-until-unchanged.3.3.3" id="ftn.cx-until-unchanged.3.3.3">3</a><span class="csq">]</span></sup> </p>
                           </div>
                           <div class="footnote-body-wrapper">
                              <p>Yes, it's a bug
                                 that there's no equivalent of <code class="tag-element">p:iteration-source</code> for this
                                 step.</p>
                           </div>
                        </div>
                     </div>
                  </div>
               </article>
            </div>
         </div>
         <div xmlns:tmpl="http://docbook.org/xslt/titlepage-templates" class="navfooter">
            <table width="100%" summary="Navigation table">
               <tr>
                  <td width="40%" align="left"><a title="cx:sparql" href="cx-sparql.html"><img src="img/prev.png" alt="Prev" border="0" /></a> </td>
                  <td width="20%" align="center"><a title="XML Calabash Reference" href="index.html"><img src="img/home.png" alt="Home" border="0" /></a></td>
                  <td width="40%" align="right"> <a title="cx:uri-info" href="cx-uri-info.html"><img src="img/next.png" alt="Next" border="0" /></a></td>
               </tr>
               <tr>
                  <td width="40%" align="left">cx:sparql </td>
                  <td width="20%" align="center"><a title="XML Calabash Extension Steps" href="cx-steps.html"><img src="img/up.png" alt="Up" border="0" /></a></td>
                  <td width="40%" align="right"> cx:uri-info</td>
               </tr>
            </table>
         </div>
         <div xmlns:tmpl="http://docbook.org/xslt/titlepage-templates" class="copyrightfooter">
            <p><a href="dbcpyright.html">Copyright</a> © 2011–2020 Norman Walsh.</p>
         </div>
      </div>
   </body>
</html>